package day11;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author yt1105
 * @version 1.0
 */
public class ArraysSortCustom {

    public static void main(String[] args) {
        int[] arr = {1, 2, -9, 28};
        bubble02(arr, new Comparator() {
            @Override
            //我们在这里具体决定我们如何进行排序处理的操作 我们自己决定
            public int compare(Object o1, Object o2) {
                int i1 = (Integer) o1;
                int i2 = (Integer) o2;
                return i1 - i2;
            }
        });
//        bubbleSort(arr);
//        System.out.println(Arrays.toString(arr));
    }

    public static void bubbleSort(int[] arr) {
        //0-n-1
        //0-n-2
        //0-n-3
        int n = arr.length - 1;
        for (int end = n - 1; end >= 0; end--) {
            for (int i = 1; i <= end; i++) {
                if (arr[i - 1] > arr[i]) {
                    int tmp = 0;
                    tmp = arr[i - 1];
                    arr[i - 1] = arr[i];
                    arr[i] = tmp;
                }
            }
        }

    }

    //1.结合冒泡+定制
    public static void bubble02(int[] arr, Comparator c) {
        int n = arr.length - 1;
        for (int end = n - 1; end >= 0; end--) {
            for (int i = 1; i <= end; i++) {
                if (c.compare(arr[i - 1], arr[i]) > 0) {//这里决定了我们的排序的顺序
                    int tmp = 0;
                    tmp = arr[i - 1];
                    arr[i - 1] = arr[i];
                    arr[i] = tmp;
                }
            }
        }

    }
}
